// 获取pc端静态资源
const getAssetsFile = (url) => {
    return new URL(`../assets/images/${url}`, import.meta.url).href
};

//金额转换
export const formatNumber = (num) => {
    if (num >= 1e8) {
        return {value: (num / 1e8).toFixed(2), unit: '亿'};
    } else if (num >= 1e4) {
        return {value: (num / 1e4).toFixed(2), unit: '万'};
    } else if (num >= 1e3) {
        return {value: (num / 1e3).toFixed(2), unit: '千'};
    } else {
        return {value: num.toString(), unit: ''};
    }
}

//百分比转换
export const formatPercentage = (num) => {
    const percentage = (num * 100).toFixed(2);
    const [integer, decimal] = percentage.split('.');
    if (decimal === '00') {
        return `${integer}%`;
    } else {
        return `${percentage}%`;
    }
}

//排名图片
export const rankingImages = (key) => {
    const img = [
        getAssetsFile('pai_1.png'),
        getAssetsFile('pai_2.png'),
        getAssetsFile('pai_3.png'),
    ]
    return img[key]
}

export default {
    formatNumber,
    formatPercentage,
    getAssetsFile,
};

